package com.ly.hotel.spainterface.nm;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ly.hotel.R;
import com.ly.hotel.common.MyApplication;
import com.ly.hotel.spainterface.nm.bean.NmXFItemBean;
import com.ly.hotel.util.ImageUtil;

import java.util.List;

public class NmXFItemAdapter extends BaseAdapter {
	private Context mContext;
	private List<NmXFItemBean> itemList;
	private int rod;
	LayoutInflater mInflater;

	public NmXFItemAdapter(Context context, List<NmXFItemBean> list){
		this.itemList = list;
		mContext = context;
		mInflater = LayoutInflater.from(mContext);
		rod = mContext.getResources().getDimensionPixelSize(R.dimen.px9);
	}

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int postion) {
		return itemList.get(postion);
	}

	@Override
	public long getItemId(int postion) {
		return postion;
	}

	@Override
	public View getView(int postion, View contentView, ViewGroup arg2) {
		ViewHolder holder;
		if (contentView == null) {
			holder = new ViewHolder();
			contentView = mInflater.inflate(R.layout.xf_gridview_item, null);
			holder.mImg = contentView.findViewById(R.id.mXFItemImage);
			holder.mTxt= contentView.findViewById(R.id.mXFItemtext);
			contentView.setTag(holder);
		} else {
			holder = (ViewHolder) contentView.getTag();
		}
		NmXFItemBean item = itemList.get(postion);
		String imgPath = MyApplication.getHostResUrl() + "/upload/interface/consume/pic/"
				+ itemList.get(postion).getId() + ".jpg";
		ImageUtil.displayImage_Round(mContext, imgPath, holder.mImg,rod);
		double price = Double.parseDouble(item.getPrice());
		holder.mTxt.setText(item.getName() + "  " + String.format("%.0f",price) +
				mContext.getResources().getString(R.string.xf_rmb));
		return contentView;
	}

	class ViewHolder {
		ImageView mImg;
		TextView mTxt;
	}
}
